package com.dhecp.framework.web.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhecp.common.utils.DateUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTableToEntity;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.base.domain.BaseInfo;
import com.dhecp.project.base.domain.BaseInfoSimple;
import com.dhecp.project.base.domain.BaseStockType;
import com.dhecp.project.base.domain.CompanyInfo;
import com.dhecp.project.base.mapper.BaseInfoMapper;
import com.dhecp.project.base.mapper.BaseStockTypeMapper;
import com.dhecp.project.base.mapper.CompanyInfoMapper;
import com.dhecp.project.finance.domain.PartnerBookedApply;
import com.dhecp.project.finance.mapper.PartnerBookedApplyMapper;
import com.dhecp.project.hr.domain.UserPerformanceRule;
import com.dhecp.project.hr.domain.UserSalary;
import com.dhecp.project.hr.domain.UserWelfare;
import com.dhecp.project.hr.mapper.UserPerformanceRuleMapper;
import com.dhecp.project.hr.mapper.UserSalaryMapper;
import com.dhecp.project.hr.mapper.UserWelfareMapper;
import com.dhecp.project.purchase.domain.PurchaseAddress;
import com.dhecp.project.purchase.domain.PurchaseOrder;
import com.dhecp.project.purchase.domain.PurchasePlan;
import com.dhecp.project.purchase.mapper.PurchaseAddressMapper;
import com.dhecp.project.purchase.mapper.PurchaseOrderMapper;
import com.dhecp.project.purchase.mapper.PurchasePlanMapper;
import com.dhecp.project.system.domain.SysDepotInfo;
import com.dhecp.project.system.domain.SysFieldForConditions;
import com.dhecp.project.system.domain.SysMenuInfo;
import com.dhecp.project.system.domain.SysUserInfoSimple;
import com.dhecp.project.system.mapper.SysDepotInfoMapper;
import com.dhecp.project.system.mapper.SysDictionaryForFieldMapper;
import com.dhecp.project.system.mapper.SysModuleSetMapper;
import com.dhecp.project.system.mapper.SysUserModuleAgentMapper;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 精简基础数据，用于调入、选择时查询使用
 * @author DH-Xxj
 * @version 2019年10月29日
 */
@Service("baseinfosimple")
public class BaseInfoSimpleService {
	
	@Autowired
	private BaseInfoMapper baseInfoMapper;
	
	@Autowired
	private CompanyInfoMapper companyInfoMapper;

	@Autowired
	private UserPerformanceRuleMapper userPerformanceRuleMapper;

	@Autowired
	private UserWelfareMapper userWelfareMapper;

	@Autowired
	private UserSalaryMapper userSalaryMapper;

	@Autowired
	private PurchasePlanMapper purchasePlanMapper;

	@Autowired
	private PurchaseOrderMapper purchaseOrderMapper;
	@Autowired
	private PurchaseAddressMapper purchaseAddressMapper;
	@Autowired
	private PartnerBookedApplyMapper partnerBookedApplyMapper;

	@Autowired
	private SysDepotInfoMapper depotInfoMapper;
	
	@Autowired
	private SysDictionaryForFieldMapper dictionaryForFieldMapper;
	
	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;
	
	@Autowired
	private SysModuleSetMapper moduleSetMapper;
	
	@Autowired
	private BaseStockTypeMapper baseStockTypeMapper;
	
	@Autowired
	private SysUserModuleAgentMapper userModuleAgentMapper;

	/**
	 * 根据字典配置的类型返回对应下拉框待选数据
	 * @param fieldSearchType
	 * @return
	 * @author DH-Xxj
	 */
	public List<BaseInfo> getDropdownData(String fieldSearchType, String fieldFrontSave, String fieldFrontShow){
		BaseInfo dropdownData0 = new BaseInfo("否");
		BaseInfo dropdownData1 = new BaseInfo("否");
		BaseInfo dropdownData2 = new BaseInfo("否");
		List<BaseInfo> dropdownList = new ArrayList<BaseInfo>();
		if (fieldSearchType == null){
			return null;//fieldSearchType为空情况下直接退出
		}
		if(fieldFrontSave==null)fieldFrontSave="";//防止传入null，后转小写报错
		if(fieldFrontShow==null)fieldFrontShow="";//防止传入null，后转小写报错
		if("special".equals(fieldSearchType.toLowerCase())){//特殊定制——定制化选项save和show分别存储key和value，以','逗号分割
				for(String i : fieldFrontSave.split(",").length<=fieldFrontShow.split(",").length?fieldFrontSave.split(","):fieldFrontShow.split(",")){
					dropdownList.add(new BaseInfo());//为防止fieldFrontSave与fieldFrontShow长度不统一，取较短的定义数组长度
				}
				int i = 0;
				for(BaseInfo bi : dropdownList){
					bi.setVid(fieldFrontSave.split(",")[i]);
					bi.setVname(fieldFrontShow.split(",")[i]);
					i++;
				}
		}else if ("yorn".equals(fieldSearchType.toLowerCase())){//是与否
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("是");
				dropdownData0.setVid("否");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("是");
			dropdownData0.setVname("否");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("yes".equals(fieldSearchType.toLowerCase())){//是与否（默认是）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("是");
				dropdownData0.setVid("否");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("是");
			dropdownData0.setVname("否");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("no".equals(fieldSearchType.toLowerCase())){	//是与否（默认否）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("是");
				dropdownData0.setVid("否");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("是");
			dropdownData0.setVname("否");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("have".equals(fieldSearchType.toLowerCase())){//有与无
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("有");
				dropdownData0.setVid("无");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("有");
			dropdownData0.setVname("无");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("havey".equals(fieldSearchType.toLowerCase())){//有与无（默认有）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("有");
				dropdownData0.setVid("无");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("有");
			dropdownData0.setVname("无");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("haven".equals(fieldSearchType.toLowerCase())){	//有与无（默认无）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("有");
				dropdownData0.setVid("无");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("有");
			dropdownData0.setVname("无");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("enable".equals(fieldSearchType.toLowerCase())){	//是否启用
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("启用");
				dropdownData0.setVid("禁用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("启用");
			dropdownData0.setVname("禁用");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("enabley".equals(fieldSearchType.toLowerCase())){	//是否启用（默认启用）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("启用");
				dropdownData0.setVid("禁用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("启用");
			dropdownData0.setVname("禁用");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("enablen".equals(fieldSearchType.toLowerCase())){	//是否启用（默认禁用）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("启用");
				dropdownData0.setVid("禁用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("启用");
			dropdownData0.setVname("禁用");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("disable".equals(fieldSearchType.toLowerCase())){	//是否禁用
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("禁用");
				dropdownData0.setVid("启用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("禁用");
			dropdownData0.setVname("启用");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("disabley".equals(fieldSearchType.toLowerCase())){	//是否禁用（默认禁用）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("禁用");
				dropdownData0.setVid("启用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("禁用");
			dropdownData0.setVname("启用");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("disablen".equals(fieldSearchType.toLowerCase())){	//是否禁用（默认启用）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("禁用");
				dropdownData0.setVid("启用");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("禁用");
			dropdownData0.setVname("启用");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("delete".equals(fieldSearchType.toLowerCase())){	//是否删除
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已删除");
				dropdownData0.setVid("未删除");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已删除");
			dropdownData0.setVname("未删除");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("deletey".equals(fieldSearchType.toLowerCase())){	//是否删除（默认已删除）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已删除");
				dropdownData0.setVid("未删除");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已删除");
			dropdownData0.setVname("未删除");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("deleten".equals(fieldSearchType.toLowerCase())){	//是否删除（默认未删除）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已删除");
				dropdownData0.setVid("未删除");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已删除");
			dropdownData0.setVname("未删除");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("effect".equals(fieldSearchType.toLowerCase())){	//是否生效
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已生效");
				dropdownData0.setVid("未生效");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已生效");
			dropdownData0.setVname("未生效");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("effecty".equals(fieldSearchType.toLowerCase())){	//是否生效（默认已生效）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已生效");
				dropdownData0.setVid("未生效");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已生效");
			dropdownData0.setVname("未生效");
			dropdownData1.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if ("effectn".equals(fieldSearchType.toLowerCase())){	//是否生效（默认未生效）
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("已生效");
				dropdownData0.setVid("未生效");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("已生效");
			dropdownData0.setVname("未生效");
			dropdownData0.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else if("year".equals(fieldSearchType.toLowerCase())){//年度
			String yearNow=DateUtils.parseDateToStr("yyyy",new Date());
			BaseInfo yearList=null;//设置为null,每次重新new，否则list的add同一对象会得到重复对象
			for(int i=-3;i<0;i++){
				yearList=new BaseInfo("否");//是否默认项
				yearList.setVid(String.valueOf(Integer.parseInt(yearNow)+i));
				yearList.setVname(String.valueOf(Integer.parseInt(yearNow)+i));
				dropdownList.add(yearList);
			}
			yearList=new BaseInfo("是");//是否默认项
			yearList.setVid(yearNow);
			yearList.setVname(yearNow);
			dropdownList.add(yearList);
			for(int i=1;i<6;i++){
				yearList=new BaseInfo("否");//是否默认项
				yearList.setVid(String.valueOf(Integer.parseInt(yearNow)+i));
				yearList.setVname(String.valueOf(Integer.parseInt(yearNow)+i));
				dropdownList.add(yearList);
			}
		}else if("monthly".equals(fieldSearchType.toLowerCase())){//月度
			String monthNow=DateUtils.parseDateToStr("MM",new Date());
			BaseInfo monthList=null;//设置为null,每次重新new，否则list的add同一对象会得到重复对象
			for(int i=1;i<=12;i++){
				monthList=new BaseInfo("否");//是否默认项
				if(i==Integer.parseInt(monthNow))monthList=new BaseInfo("是");//是否默认项
				monthList.setVid(String.valueOf(i));
				monthList.setVname(String.valueOf(i));
				dropdownList.add(monthList);
			}
		}else if ("sellreturntype".equals(fieldSearchType.toLowerCase())){	//退货状态
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData2.setVid("退到公司备货");
			}else{
				dropdownData2.setVid("companybxs");
			}
			dropdownData2.setVname("退到公司备货");
			dropdownData2.setBdefaulttext("是");	//设置为默认项
			dropdownList.add(dropdownData2);
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("退到员工备货");
			}else{
				dropdownData1.setVid("userbxs");
			}
			dropdownData1.setVname("退到员工备货");
			dropdownList.add(dropdownData1);

			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData0.setVid("退到客户备货");
			}else{
				dropdownData0.setVid("customerbxs");
			}
			dropdownData0.setVname("退到客户备货");
			dropdownList.add(dropdownData0);
		}else if ("tb_companyinfo".equals(fieldSearchType.toLowerCase())){	//公司信息
			List<CompanyInfo> companyInfoList = this.getCompanyInfo();
			Boolean firstRow = true;
			for (CompanyInfo companyInfo : companyInfoList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(companyInfo);
				Map<String, Object> entityMap = TypeUtils.entityToMap(companyInfo);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					if (firstRow){
						dropdownData.setBdefaulttext("是");	//设置为默认项
						firstRow = false;
					}
					dropdownList.add(dropdownData);
				}
			}
		}else if ("thr_userperformancerule".equals(fieldSearchType.toLowerCase())){	//员工绩效规则
			List<UserPerformanceRule> userPerformanceRules = this.getUserPerformanceRule();
			for (UserPerformanceRule item : userPerformanceRules){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("thr_userwelfare".equals(fieldSearchType.toLowerCase())){	//员工福利申请
			List<UserWelfare> userWelfareList = this.getUserWelfare();
			for (UserWelfare item : userWelfareList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("thr_usersalary".equals(fieldSearchType.toLowerCase())){	//员工薪资申请
			List<UserSalary> userSalarieList = this.getUserSalary();
			for (UserSalary item : userSalarieList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tcg_purchaseplan".equals(fieldSearchType.toLowerCase())){	//采购计划
			List<PurchasePlan> purchasePlanList = this.getPurchasePlan();
			for (PurchasePlan item : purchasePlanList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tcg_purchaseorder".equals(fieldSearchType.toLowerCase())){	//采购订单
			List<PurchaseOrder> purchaseOrderList = this.getPurchaseOrder();
			for (PurchaseOrder item : purchaseOrderList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tcg_orderall".equals(fieldSearchType.toLowerCase())){	//采购订单
			List<PurchaseOrder> purchaseOrderList = this.getAllOrder();
			for (PurchaseOrder item : purchaseOrderList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tcg_purchaseaddress".equals(fieldSearchType.toLowerCase())){	//采购订单
			List<PurchaseAddress> purchaseAddressList = this.getPurchaseAddress();
			for (PurchaseAddress item : purchaseAddressList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tcw_partnerbookedapply".equals(fieldSearchType.toLowerCase())){	//入账申请
			List<PartnerBookedApply> partnerBookedApply = this.getPartnerBookedApply();
			for (PartnerBookedApply item : partnerBookedApply){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(item);
				Map<String, Object> entityMap = TypeUtils.entityToMap(item);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("ts_depotinfo".equals(fieldSearchType.toLowerCase())){	//仓库信息
			List<SysDepotInfo> depotInfoList = this.getDepotInfo();
			for (SysDepotInfo depotInfo : depotInfoList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(depotInfo);
				Map<String, Object> entityMap = TypeUtils.entityToMap(depotInfo);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if ("tb_basestocktype".equals(fieldSearchType.toLowerCase())){	//库存类型
			List<BaseStockType> baseStockTypeList = this.getBaseStockType();
			for (BaseStockType baseStockType : baseStockTypeList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(baseStockType);
				Map<String, Object> entityMap = TypeUtils.entityToMap(baseStockType);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		}else if (fieldSearchType.toLowerCase().startsWith("tb_baseinfo_")){	//基础数据
			String vtype = fieldSearchType.toLowerCase().replace("tb_baseinfo_", "");
			List<BaseInfoSimple> baseInfoList = this.getBaseInfoSimpleData(vtype);
			for (BaseInfoSimple baseInfo : baseInfoList){
				Map<String, Object> fieldsMap = TypeUtils.entityFieldsToMap(baseInfo);
				Map<String, Object> entityMap = TypeUtils.entityToMap(baseInfo);
				BaseInfo dropdownData = this.tranDropdownData(fieldsMap, entityMap, fieldFrontSave, fieldFrontShow);
				if (dropdownData != null){
					dropdownList.add(dropdownData);
				}
			}
		} else if ("creationmethod".equals(fieldSearchType.toLowerCase())){	//货件创建方式
			if (fieldFrontSave.toLowerCase().equals(fieldFrontShow.toLowerCase())){
				dropdownData1.setVid("自动");
				dropdownData0.setVid("手动");
			}else{
				dropdownData1.setVid("1");
				dropdownData0.setVid("0");
			}
			dropdownData1.setVname("自动");
			dropdownData0.setVname("手动");
			dropdownList.add(dropdownData1);
			dropdownList.add(dropdownData0);
		}else {
			return null;
		}
		return dropdownList;
	}
	
	/**
	 * 根据字典配置取查询结果中保存和显示对应的值
	 * @param fieldsMap
	 * @param entityMap
	 * @param fieldFrontSave
	 * @param fieldFrontShow
	 * @return
	 * @author DH-Xxj
	 */
	private BaseInfo tranDropdownData(Map<String, Object> fieldsMap, Map<String, Object> entityMap, String fieldFrontSave, String fieldFrontShow){
		BaseInfo dropdownData = new BaseInfo();
		String mapKey = "";
		String mapValue = "";
		String bdefaulttext = "";
		if (fieldsMap.get("bdefaulttext") != null){
			bdefaulttext = entityMap.get(fieldsMap.get("bdefaulttext")).toString();
		}else if (fieldsMap.get("bdefault") != null){
			bdefaulttext = ("true".equals(entityMap.get(fieldsMap.get("bdefault")).toString()) ? "是" : "否");
		}else{
			bdefaulttext = "否";
		}
		
		if (fieldsMap.get(fieldFrontSave.split(",")[0].toLowerCase()) != null){
			mapKey = entityMap.get(fieldsMap.get(fieldFrontSave.split(",")[0].toLowerCase())).toString();
		}
		if (fieldsMap.get(fieldFrontShow.toLowerCase()) != null){
			mapValue = entityMap.get(fieldsMap.get(fieldFrontShow.toLowerCase())).toString();
			if ("".equals(mapKey)){
				mapKey = mapValue;
			}
		}else{
			mapValue = mapKey;
		}
		if (!"".equals(mapKey)){
			dropdownData.setVid(mapKey);
			dropdownData.setVname(mapValue);
			dropdownData.setBdefaulttext(bdefaulttext);
			if(("vid").equals(fieldFrontSave.split(",")[0].toLowerCase())){
				dropdownData.setvAccountName(entityMap.get("vAccountName") != null?entityMap.get("vAccountName").toString():"");//部分实体没有这个属性
			}else if("vaccountname".equals(fieldFrontSave.split(",")[0].toLowerCase())){
				dropdownData.setvAccountName(entityMap.get("vid").toString());
			}
			dropdownData.setFvalue(entityMap.get("fvalue") != null && !"".equals(entityMap.get("fvalue"))?Double.valueOf(entityMap.get("fvalue").toString()):0);//部分实体没有这个属性
			dropdownData.setVremark(entityMap.get("vremark") != null?entityMap.get("vremark").toString():"");//部分实体没有这个属性
		}else{
			dropdownData = null;
		}
		return dropdownData;
	}
	
	/**
	 * 查询基础数据信息
	 * @param vtype
	 * @return
	 * @author DH-Xxj
	 */
	public List<BaseInfoSimple> getBaseInfoSimpleData(String vtype){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("vtype", vtype);
		return baseInfoMapper.findBaseInfoSimpleByVtype(params);
	}

	/**
	 * 查询基础数据信息(以上级基础数据vid为限制条件，如：指定发货方式，查询发货物流)
	 * @param vtype
	 * @param pVid
	 * @return
	 * @author DH-Xxj
	 */
	public List<BaseInfoSimple> getBaseInfoSimpleDataByPVid(String vtype, String pVid){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("vtype", vtype);
		params.put("pVid", pVid);
		return baseInfoMapper.findBaseInfoSimpleByVtypeAndPVid(params);
	}
	
	/**
	 * 查询公司信息
	 * @return
	 * @author DH-Xxj
	 */
	public List<CompanyInfo> getCompanyInfo(){
		Map<String,Object> params = new HashMap<String,Object>();
		return companyInfoMapper.findCompanyInfoList(params);
	}

	/**
	 * 查询员工绩效规则
	 * @return
	 * @author DH-Xxj
	 */
	public List<UserPerformanceRule> getUserPerformanceRule(){
		Map<String,Object> params = new HashMap<String,Object>();
		return userPerformanceRuleMapper.select(params);
	}

	/**
	 * 查询员工福利申请
	 * @return
	 * @author DH-Xxj
	 */
	public List<UserWelfare> getUserWelfare(){
		Map<String,Object> params = new HashMap<String,Object>();
		return userWelfareMapper.select(params);
	}

	/**
	 * 查询员工薪资申请
	 * @return
	 * @author DH-Xxj
	 */
	public List<UserSalary> getUserSalary(){
		Map<String,Object> params = new HashMap<String,Object>();
		return userSalaryMapper.select(params);
	}

	/**
	 * 查询采购计划
	 * @return
	 * @author DH-Xxj
	 */
	public List<PurchasePlan> getPurchasePlan(){
		Map<String,Object> params = new HashMap<String,Object>();
		return purchasePlanMapper.select(params);
	}

	/**
	 * 查询采购订单
	 * @return
	 * @author DH-Xxj
	 */
	public List<PurchaseOrder> getPurchaseOrder(){
		Map<String,Object> params = new HashMap<String,Object>();
		return purchaseOrderMapper.select(params);
	}

	/**
	 * 查询全部采购订单
	 * @return
	 * @author DH-Xxj
	 */
	public List<PurchaseOrder> getAllOrder(){
		Map<String,Object> params = new HashMap<String,Object>();
		return purchaseOrderMapper.selectAllOrder(params);
	}

	/**
	 * 查询采购地址
	 * @return
	 * @author DH-Xxj
	 */
	public List<PurchaseAddress> getPurchaseAddress(){
		Map<String,Object> params = new HashMap<String,Object>();
		return purchaseAddressMapper.select(params);
	}
	/**
	 * 查询 物料入账申请
	 * @return
	 * @author DH-Xxj
	 */
	public List<PartnerBookedApply> getPartnerBookedApply(){
		Map<String,Object> params = new HashMap<String,Object>();
		return partnerBookedApplyMapper.select(params);
	}

	/**
	 * 查询仓库信息
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysDepotInfo> getDepotInfo(){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("moduleTable", "TS_DepotInfo");
		params.put("deleted", "0");
		try {
			params.put("wherestr", dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return depotInfoMapper.findDepotInfo(params);
	}

	/**
	 * 查询库存类型
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
	public List<BaseStockType> getBaseStockType(){
		Map<String,Object> params = new HashMap<String,Object>();
		return baseStockTypeMapper.findList(params);
	}

	/**
	 * 查询页面中的查询条件字段，（固定及扩展条件）
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysFieldForConditions> getFieldFrontConditions(String moduleTable) {
		return getFieldFrontConditions(moduleTable, moduleTable);
	}
	
	/**
	 * 查询页面中的查询条件字段，（固定及扩展条件）
	 * @param moduleTable
	 * @param moduleTableEntity 用于设置条件字段大小写，主要针对如单据调入时实体与字段moduleTable不一致的情况
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysFieldForConditions> getFieldFrontConditions(String moduleTable, String moduleTableEntity){
		return getFieldFrontConditions(moduleTable, moduleTableEntity, "page", "web");
	}
	
	/**
	 * 查询页面中的查询条件字段，（固定及扩展条件）
	 * @param moduleTable
	 * @param moduleTableEntity 用于设置条件字段大小写，主要针对如单据调入时实体与字段moduleTable不一致的情况
	 * @param pageType 页面类型（page：查询页面中显示的查询条件；pagecallin：调入页面中显示的查询条件）
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysFieldForConditions> getFieldFrontConditions(String moduleTable, String moduleTableEntity, String pageType){
		return getFieldFrontConditions(moduleTable, moduleTableEntity, pageType, "web");
	}
	
	/**
	 * 查询页面中的查询条件字段，（固定及扩展条件）
	 * @param moduleTable
	 * @param moduleTableEntity 用于设置条件字段大小写，主要针对如单据调入时实体与字段moduleTable不一致的情况
	 * @param pageType 页面类型（page：查询页面中显示的查询条件；pagecallin：调入页面中显示的查询条件）
	 * @param systemType 系统类型（web：网页端；mobile：手机端）
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysFieldForConditions> getFieldFrontConditions(String moduleTable, String moduleTableEntity, String pageType, String systemType) {
		Map<String, Object> params = new HashMap<String, Object>();
		moduleTable = (moduleTable == null ? "null" : moduleTable);
		moduleTableEntity = (moduleTableEntity == null ? moduleTable : moduleTableEntity);
		pageType = (pageType == null ? "page" : pageType);
		systemType = (systemType == null ? "web" : systemType);
		params.put("moduleTable",moduleTable);
		params.put("loginUser", ShiroUtils.getMandatorId());
		params.put("getFieldAttributesType", pageType);
		params.put("getFieldAttributesSystemType", systemType);
		
		List<SysFieldForConditions> conditionsList = dictionaryForFieldMapper.findFieldFrontConditions(params);
		Map<String, Object> resMap = ModuleTableToEntity.queryEntityByModuleTable(moduleTableEntity);
		if (resMap.get("entity") == null){
			return conditionsList;
		}
		Map<String, Object> entityFieldMap = TypeUtils.entityFieldsToMap(resMap.get("entity"));
		
		for (SysFieldForConditions dicFields : conditionsList){
			if (entityFieldMap.get(dicFields.getFields().toLowerCase()) != null && !"".equals(entityFieldMap.get(dicFields.getFields().toLowerCase()))){
				String field = entityFieldMap.get(dicFields.getFields().toLowerCase()).toString();
				dicFields.setFields(field);
            }
		}
		return conditionsList;
	}

	/**
	 * 查询二级菜单可做为查询条件的字段（查询条件下拉选择）
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysMenuInfo> getMenuFieldFrontConditions(String isSet) {
		Map<String, Object> params = new HashMap<String, Object>();
		if(isSet.equals("isSet")){
			params.put("isSet", true);
		}else{
			params.put("isSet", false);
		}
		params.put("userId", ShiroUtils.getMandatorId());
		return moduleSetMapper.findMenuFieldFrontConditions(params);
	}
	
	/**
	 * 查询指定用户可代理的用户列表
	 * @param agentuser
	 * @return
	 * @author DH-Xxj
	 */
	public List<SysUserInfoSimple> getUserAgentMandator(String userName){
		return userModuleAgentMapper.findUserAgentMandator(userName);
	}
	
}
